package com.car.loan.project.xr.mapper;

import com.car.loan.project.xr.domain.Customer;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.car.loan.project.xr.domain.Loan;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.security.core.parameters.P;
import org.springframework.stereotype.Repository;

/**
 * 客户基本信息Mapper接口
 *
 * @author ruoyi
 * @date 2019-11-03
 */
@Repository
public interface CustomerMapper extends BaseMapper<Customer> {

    /**
     * 根据名称 还款卡号or身份证 查询用户id
     */
    @Select("SELECT cu.id as customerId, l.id as id  \n"
        + "FROM xr_customer cu\n"
        + "LEFT JOIN xr_loan l ON l.customer_id = cu.id\n"
        + "LEFT JOIN xr_loan_detail de ON de.loan_id = l.id\n"
        + "LEFT JOIN xr_loan_status ls ON ls.loan_id = l.id\n"
        + "WHERE ls.repayment_info_status = 1\n"
        + " AND cu.name = #{name}  AND ( cu.id_card_No = #{cardNo} OR de.repay_card_no = #{cardNo}) \n")
    List<Loan> selectIdsByNameAndCardIdOrRepayCardNo(@Param("name") String name,
        @Param("cardNo") String cardNo);

}
